package com.ninthgroup.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ninthgroup.entity.Doctor;
import com.ninthgroup.mapper.DoctorMapper;
import com.ninthgroup.service.DoctorService;
import com.ninthgroup.vo.DoctorVo;
import com.ninthgroup.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：1452863884@qq.com rcg
 * @date ：Created in 2022/10/17 8:31
 * @description：员工(医生)的接口实现
 * @modified By：
 * @version:1.0
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public Result selectAllAndPage(Integer currentPage, Integer pageSize, DoctorVo doctorVo) {
        PageHelper.startPage(currentPage,pageSize);
        List<Doctor> doctors = doctorMapper.selectAll(doctorVo.getdName(), doctorVo.getdTelphone());

        PageInfo<Doctor> pageInfo=new PageInfo<>(doctors);
        return new Result(2000,"查询成功",pageInfo);
    }

    @Override
    public Result updateStatus(Integer did,Integer status) {
        if(status ==0){
            Doctor doctor = new Doctor();
            doctor.setdId(did);
            doctor.setdStatus(1);
            doctorMapper.updateByPrimaryKeySelective(doctor);

            return new Result(200,"修改状态成功(离职变在职)");
        }else {
            Doctor doctor1 = new Doctor();
            doctor1.setdId(did);
            doctor1.setdStatus(0);
            doctorMapper.updateByPrimaryKeySelective(doctor1);

            return new Result(200,"修改状态成功(在职变离职)");
        }

    }

    @Override
    public Result deleteDid(Integer did) {
        doctorMapper.deleteByPrimaryKey(did);
        return new Result(200,"删除职员(医生)成功");
    }

    @Override
    public Result updateDoctor(Doctor doctor) {
        doctorMapper.updateByPrimaryKeySelective(doctor);
        return new Result(200,"修改医生信息成功");
    }

    @Override
    public Result insertDoctor(Doctor doctor) {
        doctorMapper.insertSelective(doctor);
        return new Result(200,"添加医生信息成功");
    }

    @Override
    public Doctor findnameandpwd(Doctor doctor) {
        Doctor doctor1 = doctorMapper.findByDoctornameAndPassword(doctor.getdName(), doctor.getdPassword());
        return doctor1;
    }

    @Override
    public Result findOneById(Integer dId) {
        Doctor doctor = doctorMapper.selectByPrimaryKey(dId);
        return new Result(200,"刷新描述",doctor);
    }

    @Override
    public Result findManyTable(Integer dId) {
        List<Doctor> doctors = doctorMapper.selectManyTable(dId);
        return new Result(200,"查询成功",doctors);
    }

    @Override
    public Result selectAllDoctorAndScheuing() {
        List<Doctor> doctors = doctorMapper.selectAllToScheduing();
        return new Result(200,"查询成功",doctors);
    }



    /**
     * 按照性别查找数量
     *
     * @return
     */
    @Override
    public Result selectBysex() {
        int man = doctorMapper.selectSexMan();
        int women = doctorMapper.selectSexWomen();
        List<Integer> sex = new ArrayList<Integer>();
        sex.add(man);
        sex.add(women);
        return new Result(200, "查询成功", sex);
    }

    /**
     * 按照年龄查找数量
     *
     * @return
     */
    @Override
    public Result selectByAge() {
        int i = doctorMapper.selectByAge0_20();
        int i1 = doctorMapper.selectByAge20_40();
        int i2 = doctorMapper.selectByAge40_60();
        int i3 = doctorMapper.selectByAge60();
        List<Integer> age = new ArrayList<Integer>();
        age.add(i);
        age.add(i1);
        age.add(i2);
        age.add(i3);
        return new Result(200, "查询成功", age);
    }


}